package com.foryou.wechat.controller;

import com.alibaba.fastjson.JSONObject;
import com.foryou.wechat.model.Query;
import com.foryou.wechat.model.dto.ShootDTO;
import com.foryou.wechat.service.ShootService;
import com.foryou.wechat.utils.HttpContextUtils;
import com.foryou.wechat.utils.Response;
import com.foryou.wechat.utils.ValidatorUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by Lee.
 */
@RestController
@RequestMapping("/v/shoot")
public class ShootController {

    private final ShootService shootService;

    public ShootController(ShootService shootService) {
        this.shootService = shootService;
    }

    @PostMapping("/addShoot")
    public Response addShoot(@RequestBody ShootDTO shootDTO) {
        ValidatorUtils.validateEntity(shootDTO);
        return shootService.addShoot(shootDTO);
    }

    @GetMapping("/getShootDetail")
    public Response getShootDetail(@RequestParam Long shootId) {
        return shootService.getShootDetailById(shootId);
    }

    @PostMapping("/getForShootDetail/{id}")
    public JSONObject getShootForDetail(@PathVariable("id") Long shootId) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("data", shootService.getShootDetailById(shootId).getData());
        return jsonObject;
    }


    @GetMapping("/getUserShootList")
    public Response getUserShootList(@RequestParam(defaultValue = "0") int start, Long userId) {
        return shootService.getUserShootList(start, userId);
    }

    @PostMapping("/getShootList")
    public Response getShootList(@RequestBody Query query) {
        return shootService.getShootList(query);
    }

    @PostMapping("/getIsFollowShootList")
    public Response getIsFollowShootList(@RequestBody Query query) {
        return shootService.getIsFollowShootList(query);
    }

    @GetMapping("/collectShoot")
    public Response collectShoot(Long shootId) {
        return shootService.collectShoot(shootId);
    }

    @GetMapping("/cancelShoot")
    public Response cancelShoot(Long shootId) {
        return shootService.cancelShoot(shootId);
    }

    @GetMapping("/getCollectShootList")
    public Response getCollectShootList(@RequestParam(defaultValue = "0") int start) {
        return shootService.queryCollectShootList(start, HttpContextUtils.getUserId());
    }
}
